<template>
    <div class="table_div">
        <page-list :loading="loading" :table-config="tableConfig" :data-list="dataList" :height="height" show-index
                   show-page :total="total" :currentPage="param.pageNum" :pageSize="param.pageSize" @currentChange="handleCurrentChange"
                   show-operate operate-width="120">
            <template #searchArea>
                <el-input v-model="param.configCode" clearable placeholder="配置编号" style="width: 200px;"></el-input>
                <el-input v-model="param.configName" clearable placeholder="配置名称" style="width: 200px;"></el-input>
                <el-button type="primary" @click="searchList">查询</el-button>
                <el-button type="primary" @click="resetData">重置</el-button>
                <el-button type="primary" @click="showInsert()">新增</el-button>
            </template>

            <template #item_enableFlag="scope">
                {{ $common.getDicName('yesNo', scope.row.enableFlag) }}
            </template>

            <template #operateContent="scope">
                <el-button type="text" @click="showUpdate(scope.row.configCode)">编辑</el-button>
                <el-popconfirm title="是否确定删除当前数据？" @confirm="delData(scope.row.configCode)">
                    <el-button slot="reference" type="text">删除</el-button>
                </el-popconfirm>
            </template>
        </page-list>
        <!--新增-->
        <constant-insert :visible.sync="editInsert" @refreshList="searchList"></constant-insert>
        <!--修改-->
        <constant-update :config-key="configCode" :visible.sync="editUpdate" @refreshList="searchList"></constant-update>
    </div>
</template>

<script>
import PageList from "@/components/grid/pageList";
import ConstantInsert from "./component/constantInsert";
import ConstantUpdate from "./component/constantUpdate";

export default {
    name: "systemConfig",
    components: {ConstantUpdate, ConstantInsert, PageList},
    data() {
        return {
            height: '500px',
            loading: false,
            editInsert: false,
            editUpdate: false,

            configCode: '',
            tableConfig: [
                {label: "配置编号", prop: "configCode", minWidth: 300},
                {label: "配置名称", prop: "configName", minWidth: 300},
                {label: "配置值", prop: "configValue", width: 400},
                {label: "启用", prop: "enableFlag", width: 60, slot: true},
            ],
            dataList: [],
            total: 0,
            param: {
                configCode: '',
                configName: '',
                field: 'config_key',
                order: 'desc',
                pageSize: 20,
                pageNum: 1,
            },
        }
    },
    mounted() {
        this.$nextTick(() => {
            this.height = (document.body.offsetHeight - 185) + "px";
        })
        this.searchList();
    },
    methods: {
        handleCurrentChange(val) {
            this.param.pageNum = val;
            this.searchList();
        },
        resetData() {
            this.param.configCode = '';
            this.param.configName = '';
            this.searchList();
        },
        searchList() {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/baseConstant/getAllList", this.param).then(res => {
                this.dataList = res.data;
            }).finally(() => {
                this.loading = false;
            })
        },
        showInsert() {
            this.editInsert = true;
        },
        showUpdate(configCode) {
            this.configCode = configCode;
            this.editUpdate = true;
        },
        delData(configCode) {
            this.loading = true;
            this.$axios.post("/CHILD_SYSTEM/baseConstant/delete/" + configCode).then(res => {
                this.searchList();
                this.$message.success(res.message);
            }).finally(() => {
                this.loading = false;
            })
        },
    },
}
</script>

<style scoped>

</style>